package com.wsc.personalblog.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String TOPIC_EXCHANGE = "topicExchange";
    public static final String NORMAL_QUEUE = "normal_Exchange";
    public static final String N_Q_ROUTING_KEY = "code";


    /**
     * 声明普通交换机
     *
     * @return
     */
    @Bean("topicExchange")
    public TopicExchange getDirectExchange() {
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    /**
     * 声明普通队列
     * @return
     */
    @Bean("normalQueue")
    public Queue getQueue(){
        return QueueBuilder.durable(NORMAL_QUEUE).build();
    }

    /**
     * 绑定普通队列到延迟交换机
     * @return
     */
    @Bean
    public Binding BindingNormalQueue(@Qualifier("normalQueue") Queue normalQueue ,
                                      @Qualifier("topicExchange") TopicExchange topicExchange){
        return BindingBuilder.bind(normalQueue).to(topicExchange).with(N_Q_ROUTING_KEY);
    }

}
